home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / Snippets / Development Tools & Languages / UserFunction Gestalt / UserChkGestaltFunction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-21  |  2.8 KB  |  102 lines  |  [TEXT/MPS ]

  1. /*------------------------------------------------------------------------------
  2.  *
  3.  *    Apple Macintosh Developer Technical Support
  4.  *
  5.  *  Installer 3.4.3 sample: UserChkGestaltFunction
  6.  *
  7.  *    File:        UserChkGestaltFunction.c -    c Source
  8.  *
  9.  *    by:            Rich Kubota
  10.  *  
  11.  *
  12.  *  purpose: Use as a alternate means of identifying whether a Gestalt selector
  13.  *            is available.  The CheckGestalt clause requires the scriptor to enter
  14.  *            all valid Gestalt selector results.  This poses a future compatibility
  15.  *            problem in that one would like to simply know that a gestalt selector
  16.  *            exists and not have to worry about matching the result in order to pass
  17.  *            the clause.  This user function simply requires that the scriptor pass in 
  18.  *            the gestalt selector to check for.  A true result is returned if the selector
  19.  *            is found, false otherwise or if the Gestalt trap was not available.
  20.  *    Copyright © 1988 - 1994 Apple Computer, Inc.
  21.  *    All rights reserved.
  22.  *
  23.  *----------------------------------------------------------------------------*/
  24. #if 0
  25. c -b UserChkGestaltFunction.c
  26. Link -ra =resPurgeable -rt infn=1002 -rn -m USERCHKGESTALTFUNCTION -t rsrc -c RSED ∂
  27.         UserChkGestaltFunction.c.o ∂
  28.         "{Libraries}"Interface.o ∂
  29.         -o UserChkGestaltFunction.rsrc
  30. #endif
  31.  
  32. /* applec is only defined by MPW C so we can use it to make versions that work
  33.   with MPW C and THINK C
  34.  */
  35. #ifdef applec
  36. #include <Types.h>
  37. #include <Traps.h>
  38. #include <OSUtils.h>
  39. #include <GestaltEqu.h>
  40. #endif
  41.  
  42.  
  43. /******************  function prototypes  *********************/
  44.  
  45. short         NumToolboxTraps(void);
  46. TrapType     GetTrapType(unsigned short theTrap);
  47. Boolean     TrapAvailable(unsigned short theTrap);
  48.  
  49. /**************************************************************/
  50.  
  51. pascal Boolean UserChkGestaltFunction(short targetVRefNum, long blessedID, long selector)
  52. {
  53. #pragma unused (blessedID, targetVRefNum)
  54.  
  55.     OSErr    err;
  56.     long    result;
  57.     
  58.     if (TrapAvailable(_Gestalt))        // check whether the Gestalt trap is available
  59.     {
  60.         err = Gestalt((OSType)selector, &result);    // pass the selector to the Gestalt call
  61.         return (err == noErr);        // return result
  62.     }
  63.     else
  64.         return false;                // gestalt not found, return false
  65. }
  66.  
  67. /******** The following code is from IM VI *******/
  68.  
  69. short NumToolboxTraps(void)
  70. {    
  71.     if (NGetTrapAddress(_InitGraf, ToolTrap) == 
  72.         NGetTrapAddress(0xAA6E, ToolTrap))
  73.         return(0x200);
  74.     else
  75.         return(0x400);
  76. }
  77.  
  78. #define TrapMask    0x0800
  79.  
  80. TrapType GetTrapType(unsigned short theTrap)
  81. {
  82.     if (theTrap & TrapMask)
  83.         return (ToolTrap);
  84.     else
  85.         return (OSTrap);
  86. }
  87.  
  88. Boolean TrapAvailable(unsigned short theTrap)
  89. {
  90.     TrapType    theType;
  91.     
  92.     theType = GetTrapType(theTrap);
  93.     if (theType == ToolTrap) {
  94.         theTrap &= 0x07FF;
  95.         if (theTrap >= NumToolboxTraps())
  96.             theTrap = _Unimplemented;
  97.     }
  98.     
  99.     return (NGetTrapAddress(theTrap, theType) != 
  100.             NGetTrapAddress(_Unimplemented, ToolTrap));
  101. }
  102.